# Contributor: Jaroslaw Swierczynski <swiergot@aur.archlinux.org>
# Maintainer: Daenyth <Daenyth+Arch AT gmail DOT com>

pkgname=skype
pkgver=4.1.0.20
pkgrel=6
arch=(i686 x86_64)
pkgdesc="P2P software for high-quality voice communication"
url="http://www.skype.com/"
license=('custom')
options=('!strip')
install=skype.install
depends=(xdg-utils hicolor-icon-theme)
conflicts=('skype-staticqt')

if [[ $CARCH == i686 ]]; then
  depends+=(qt4 alsa-lib libxss libxv libxcursor v4l-utils gstreamer0.10-base)
  optdepends=('libcanberra: XDG sound support'
              'pulseaudio: PulseAudio support')
else
  depends+=(lib32-{qt4,alsa-lib,libxss,libxv,libxcursor,v4l-utils})
  optdepends=('lib32-libcanberra: XDG sound support'
              'lib32-libpulse: PulseAudio support')
  conflicts+=(bin32-skype bin32-skype-staticqt)
  provides=("bin32-skype=$pkgver")
  replaces=(bin32-skype)
fi

source=(http://download.skype.com/linux/$pkgname-$pkgver.tar.bz2 PERMISSION skype-wrapper
        ftp://ftp.archlinux.org/other/$pkgname/qtwebkit-2.2.2-i686.tar.xz)
md5sums=('fe41f6b36e96730161c0f9332b001575'
         '26e1772379d4d4df9471b6ed660a6d97'
         '66985be1d7b953fb9f73ba6ed749812b'
         '42c01ffa98e32b59605403efb42c8821')

package() {
  cd "$srcdir/$pkgname-$pkgver"

  if [[ $CARCH == i686 ]]; then
	  libdir="usr/lib"
  
      # FS#33417 - Skype wants qtwebkit 2.2.x
      install -Dm755 "${srcdir}"/libQtWebKit.so.4 "${pkgdir}"/usr/share/skype/lib/libQtWebKit.so.4
  else
	  libdir="usr/lib32"
  fi

  install -d "$pkgdir/usr/bin"
  sed "s#@LIBDIR@#/$libdir#" "$srcdir/skype-wrapper" > "$pkgdir/usr/bin/skype"
  chmod 755 "$pkgdir/usr/bin/skype"

  # Executable
  install -D skype "$pkgdir/$libdir/skype/skype"

  # Data
  mkdir -p "$pkgdir"/usr/share/skype/{avatars,lang,sounds}
  install -m 644 avatars/* "$pkgdir/usr/share/skype/avatars"
  install -m 644 lang/*    "$pkgdir/usr/share/skype/lang"
  install -m 644 sounds/*  "$pkgdir/usr/share/skype/sounds"

  # DBus Service
  install -Dm 644 skype.conf \
    "$pkgdir/etc/dbus-1/system.d/skype.conf"

  # Icons
  for _i in 16 32 48; do
    install -Dm 644 icons/SkypeBlue_${_i}x${_i}.png \
      "$pkgdir/usr/share/icons/hicolor/${_i}x${_i}/apps/skype.png"
  done
  install -Dm 644 icons/SkypeBlue_48x48.png \
    "$pkgdir/usr/share/pixmaps/skype.png"

  # Desktop file
  install -Dm 644 skype.desktop \
    "$pkgdir/usr/share/applications/skype.desktop"

  # License
  install -Dm 644 LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm 644 "$srcdir/PERMISSION" \
    "$pkgdir/usr/share/licenses/$pkgname/PERMISSION"
}
